//
//  WSZCustomPickView.m
//  Bob
//
//  Created by apple on 16/8/17.
//  Copyright © 2016年 com.xabeiying. All rights reserved.
//

#import "WSZCustomPickView.h"

@implementation WSZCustomPickView
-(void)awakeFromNib
{
    [super awakeFromNib];
    
//    [self.transView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self).offset(62.5 * SCREENH6);
////        make.trailing.mas_equalTo(self).offset(-62.5 * SCREENH6);
//        make.top.mas_equalTo(self).offset(258.5 * SCREENH6);
////        make.bottom.mas_equalTo(self).offset(-258.5 * SCREENH6);
//        make.width.mas_equalTo(250 * SCREENH6);
//        make.height.mas_equalTo(150 * SCREENH6);
//    }];
//    
//    
//    
//    self.bottomView.backgroundColor = [UIColor redColor];
//    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.trailing.mas_equalTo(self.transView);
//        make.height.mas_equalTo(39 * SCREENH6);
//        make.bottom.mas_equalTo(self.transView);
//    }];
//    
//    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(1 * SCREENH6);
//        make.leading.trailing.mas_equalTo(self.transView);
//        make.bottom.mas_equalTo(self.bottomView.top).offset(-1 * SCREENH6);
//    }];
//    
//    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.top.leading.trailing.mas_equalTo(self.bottom);
//    }];
//    
//    if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
//        
//        [self.datePickView mas_makeConstraints:^(MASConstraintMaker *make) {
//            //        make.width.mas_equalTo(250 * SCREENH6);
//            make.height.mas_equalTo(100 * SCREENH6);
//            make.top.mas_equalTo(self.transView);
//            make.width.mas_equalTo(250 * SCREENH6);
//            make.leading.trailing.mas_equalTo(self.transView);
//            make.bottom.mas_equalTo(self.lineView.mas_top);
//            //        make.bottom.mas_equalTo();
//            //        make.bottom.mas_equalTo(self.sureBtn.mas_top);
//        }];
//    }else{
//        
//        [self.datePickView mas_makeConstraints:^(MASConstraintMaker *make) {
//            //        make.width.mas_equalTo(250 * SCREENH6);
//            make.height.mas_equalTo(80 * SCREENH6);
//            make.top.mas_equalTo(self.transView);
//           make.width.mas_equalTo(250 * SCREENH6);
//            make.leading.trailing.mas_equalTo(self.transView);
//            make.bottom.mas_equalTo(self.bottomView.mas_top);
//        }];
//    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+(WSZCustomPickView *)standViewWithDataArr:(NSArray *)dataArr Task:(void (^)(NSInteger, id model))completeBlock
{
    WSZCustomPickView * view = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
    view.datePickView.delegate = view;
    view.datePickView.dataSource = view;
    view.dataArr = dataArr;
    view.clickBlock = completeBlock;
    
    return view;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.dataArr.count;
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel * label = [[UILabel alloc] init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:18 * SCREENH6];
    label.textColor = [UIColor darkGrayColor];
    id model = self.dataArr[row];
    if([model isKindOfClass:[MemberInfoTypeModel class]])
    {
        MemberInfoTypeModel * type = model;
        label.text = type.name;
    }else if ( [model isKindOfClass:[NSString class]])
    label.text = self.dataArr[row];
    return label;
}


-(void)show
{
    self.frame = [UIScreen mainScreen].bounds;
    self.markBtn.alpha = 0;
    self.transView.transform = CGAffineTransformMakeScale(1.2 * SCREENH6, 1.2 * SCREENH6);
    self.transView.alpha = 0;
    [self layoutIfNeeded];
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.markBtn.alpha = 1;
        self.transView.transform = CGAffineTransformIdentity;
        self.transView.alpha = 1;
        [self layoutIfNeeded];
    }];
}

-(void)cannel
{
    self.showLayout.constant = -256 * SCREENH6;
    [UIView animateWithDuration:0.3 animations:^{
        [self layoutIfNeeded];
        self.markBtn.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)completeTask:(id)sender {
    [self cannel];
    if(self.clickBlock)
    {
        
        self.clickBlock([self.datePickView selectedRowInComponent:0],self.dataArr[[self.datePickView selectedRowInComponent:0]]);
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"check" object:nil];
    }
}

- (IBAction)cannelTask:(id)sender {
    [self cannel];
}

@end
